<template>
	<view class="orderListWrapper">
		<view class="listWrapper">
			<view v-for="item in dataList" class="item" :key="item.OrderId" v-if="dataList.length>0">
				<!-- <image class="item-icon"></image> -->
				<view class="item-header">
					<view class="item-title">单号:{{item.OrderId}}</view>
				</view>
				<view v-for="shop in item.shops" class="shopItem">
					<!-- <image class="shop-icon"></image> -->
					<view class="shop-title">{{shop.ProductName}}</view>
					<view class="shop-price">¥{{(shop.Price/100).toFixed(2)}}</view>
					<view class="shop-nums">x{{shop.Nums}}</view>
				</view>
				<view class="item-bottom">
					<view class="item-bottom-total"><text class="shifu">实付:</text>¥{{(item.PayPrice/100).toFixed(2)}}</view>
				</view>
				<view class="item-bottom-button">
					<view class="item-time">{{item.AddTimeStr}}</view>
					<view class="item-bottom-video" v-on:click="onVideos(item)">查看视频</view>
					<view class="item-bottom-tiaokuan" v-on:click="onTiaoKuan">申请调款</view>
				</view>
			</view>
		</view>
		<view class="emptyWrapper" v-if="dataList.length==0">
			<image src="../../static/qiridingdan.png" mode="aspectFit"></image>
			<view class="title">暂无订单</view>
		</view>
	</view>
</template>

<script>
	import http from '../../common/http.js';
	import common from '../../common/common.js';
	
	export default {
		data() {
			return {
				lastid:0,
				noMore:false,
				isLoadingMore:false,
				dataList:[],
				storeid:''
			}
		},
		onLoad(options) {
			this.storeid = options.storeid
			this.refreshData()
		},
		onPullDownRefresh() {
			this.isLoadingMore = false
			this.lastid = 0
			this.refreshData()
		},
		onReachBottom() {
			if (this.noMore == false) {
				this.isLoadingMore = true
				this.refreshData()
			}
		},
		methods: {
			refreshData(){
				var self = this
				http.get("/store/order/list", {"lastid":self.lastid, "storeid":this.storeid}, (res)=>{
					uni.stopPullDownRefresh()
					var orderList = res.orderlist
					for (var i=0;i<orderList.length;i++) {
						var item = orderList[i]
						item["AddTimeStr"] = common.formatTime(item.AddTime)
					}
					if (orderList.length > 0){
						self.lastid = orderList[orderList.length-1]["Id"]
					}
					for (var index=0;index<orderList.length;index++) {
						orderList[index]["shops"] = res.sellarray[index]
					}
					
					if (self.isLoadingMore) {
						self.dataList = self.dataList.concat(orderList)
					}else{
						self.dataList = orderList
					}
					
					if (orderList.length == 0) {
						self.noMore = true
					}else{
						self.noMore = false
					}
					
				})
			},
			onTiaoKuan() {
				common.showKefu()
			},
			onVideos(item) {
				http.get("/store/enterdetail", {"id":item.Eid}, (res)=>{
					uni.navigateTo({
						url:"../shebei/shebei?s="+res.EnterTime+"&e="+res.LeaveTime+"&storeid="+this.storeid
					})
				})
			}
		}
	}
</script>

<style>
	.shifu {
		color: #333333;
		font-size: 14px;
	}
	.item-header {
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #f6f6f6;
		height: 30px;
		line-height: 25px;
	}
	.consumWrapper {
		background-color: #f6f6f6;
		height: 100%;
	}
	.listWrapper {
		background-color: #f6f6f6;
		padding: 10px 10px;
	}
	.item {
		padding: 10px 10px;
		box-sizing: border-box;
		background-color: white;
		margin-bottom: 10px;
		border-radius: 8px;
	}
	.item-title {
		font-size: 14px;
		color: #8B8B8B;
		font-weight: 500;
	}
	.shopItem {
		height: 50px;
		position: relative;
		/* border-bottom: 1rpx solid #f3f3f2; */
		padding: 5px 0px;
		box-sizing: border-box;
	}
	.shop-icon {
		width: 40px;
		height: 40px;
		background-color: red;
		position: absolute;
		left: 0px;
	}
	.shop-title {
		top: 5px;
		position: absolute;
		max-lines: 2;
		width: 60%;
		color: #8B8B8B;
		font-size: 14px;
		/* font-weight: 300; */
		
	}
	.shop-price {
		top: 5px;
		position: absolute;
		right: 0px;
		height: 20px;
		line-height: 20px;
		font-size: 16px;
		color: #FE3636;
	}
	.shop-nums {
		position: absolute;
		top: 25px;
		right: 0px;
		font-size: 12px;
		color: #FE3636;
	}
	.item-bottom {
		/* border-bottom: 1rpx solid #f3f3f2; */
		/* border-top: 1rpx solid #f3f3f2; */
		font-size: 16px;
		color: #FE3636;
		text-align: right;
		height: 30px;
		line-height: 36px; 
		display: flex;
		flex-direction: row-reverse;
		/* justify-content: space-between; */
		height: 40px;
	}
	.item-bottom-button {
		font-size: 16px;
		color: red;
		text-align: right;
		height: 30px;
		line-height: 36px; 
		display: flex;
		justify-content: space-between;
		flex-wrap: nowrap;
		align-items: center;
		height: 40px;
	}
	.item-time {
		color: #8B8B8B;
		font-size: 12px;
		
	}
	.storename {
		color: #222222;
		height: 30px;
		line-height: 30px;
		font-size: 14px;
	}
	.item-bottom-button {
		height: 25px;
	}
	.item-bottom-tiaokuan, .item-bottom-video {
		color: #75D7E0;
		border:1px solid #75D7E0;
		font-size: 13px;
		width: 82px;
		border-radius: 18px;
		text-align: center;
		line-height: 25px;
		height: 25px;
		float: right;
	}
</style>
